var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var webpackConfig = require('./webpack.config');

var port = process.env.NODE_PORT || 3030;

var express = require('express');
var app = express();
// app.use(serveStatic(path.resolve(__dirname, "src"), {
// 	maxAge: 365 * 24 * 60 * 60
// }));
require('./routes')(app);

var http = require('http');
var backServer = http.createServer(app);
backServer.listen((port+1), function(){
    console.log('BackServer is now running on port '+(port+1)+'!');

});

var server = new WebpackDevServer(webpack(webpackConfig), {
    publicPath: webpackConfig.output.publicPath,
    hot: true,
    noInfo: false,
    historyApiFallback: true,
    contentBase:'./src/',
    proxy: {
        "/api/*": webpackConfig.output.proxy
    }
});
server.listen(port, '127.0.0.1', function (err, result) {
    if (err) {
        console.log(err);
    }
    console.log('App is now running on port : '+port+'!');
});



// var path = require('path');
// var express = require('express');
// var webpack = require('webpack');
// var config = require('./webpack.config.dev');
//
// var app = express();
// var compiler = webpack(config);
//
// app.use(require('webpack-dev-middleware')(compiler, {
//   noInfo: true,
//   publicPath: config.output.publicPath
// }));
//
// app.use(require('webpack-hot-middleware')(compiler));
//
// app.use('/public', express.static('public'));
//
// app.get('*', function(req, res) {
//   res.sendFile(path.join(__dirname, 'index.html'));
// });
//
// app.listen(3000, function(err) {
//   if (err) {
//     console.log(err);
//     return;
//   }
//
//   console.log('Listening at http://localhost:3000');
// });


/* eslint-disable */
// var isDev = (process.env.NODE_ENV !== 'production');
// var webpack = require('webpack');
// var express = require('express');
// var path = require('path');
// var app = express();
//
// if (!isDev) {
//     var static_path = path.join(__dirname);
//
//     app.use(express.static(static_path))
//     .get('/', function (req, res) {
//         res.sendFile('./index.html', {
//             root: static_path
//         });
//     }).listen(process.env.PORT || 8080, function (err) {
//         if (err) { console.log(err) };
//         console.log('Listening at localhost:8080');
//     });
// }
//
//
// if (isDev) {
//     var config = require('./webpack.config');
//     var compiler = webpack(config);
//
//     require('./fakeAPI');
//
//   app.use(require('webpack-dev-middleware')(compiler, {
//       noInfo: true,
//       publicPath: config.output.publicPath
//   }));
//
//   app.use(require('webpack-hot-middleware')(compiler));
//
//   app.get('*', function(req, res) {
//     res.sendFile(path.join(__dirname, 'index.html'));
//   });
//
//   app.listen(3000, 'localhost', function(err) {
//     if (err) {
//       console.log(err);
//       return;
//     }
//     console.log('Listening at localhost:3000');
//   });
// }
